package com.atguigu.yygh.hosp.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.utils.HttpRequestHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/*==========================================
      时 间:   2022-03-07
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
 ==========================================*/
@RequestMapping(value = "/api/hosp")
@RestController
public class ApiDepartmentController {


   @Autowired
   private DepartmentService departmentService;


   @PostMapping("/department/remove")
   public R  remove(HttpServletRequest httpServletRequest){
       Map<String, Object> paramMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
       departmentService.remove(paramMap);
       return R.ok().code(200);
   }

   @PostMapping(value = "/department/list")
   public R getDepartmentPage(HttpServletRequest httpServletRequest){
       Map<String, Object> paramMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
       //TODO：sign key
       Page page=departmentService.getDepartmentPage(paramMap);
       return R.ok().code(200).data(JSONObject.parseObject(JSONObject.toJSONString(page),Map.class));
   }

    @PostMapping(value = "/saveDepartment")
    public R saveDepartment(HttpServletRequest httpServletRequest){
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
        //TODO: sign key校验
        departmentService.saveDepartment(paramMap);
        return R.ok().code(200);
    }
}
